package com.gls.framework.service.core.support;

import org.springframework.cloud.security.oauth2.client.AccessTokenContextRelay;
import org.springframework.security.oauth2.client.OAuth2RestTemplate;
import org.springframework.security.oauth2.client.resource.UserRedirectRequiredException;
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails;
import org.springframework.security.oauth2.common.OAuth2AccessToken;

/**
 * @author lizhiyong
 */
public class CustomOauth2RestTemplate extends OAuth2RestTemplate {

    public CustomOauth2RestTemplate() {
        super(new ClientCredentialsResourceDetails());
    }

    @Override
    public OAuth2AccessToken getAccessToken() throws UserRedirectRequiredException {
        AccessTokenContextRelay accessTokenContextRelay = new AccessTokenContextRelay(getOAuth2ClientContext());
        accessTokenContextRelay.copyToken();
        return super.getAccessToken();
    }
}
